package com.wanxi.tcp.demo4客户端发送文件给服务器;

import java.io.*;
import java.net.Socket;

/**
 * TCP 客户端,演示客户端上传文本文件到服务器端
 */
public class TCPClient {
    public static void main(String[] args) throws IOException {
        System.out.println("tcp 客户端启动......");
        //1 创建客户端socket
        Socket socket = new Socket("127.0.0.1", 30000);
        //2 创建要读取的文件流
        String path = "E:\\wanxi\\step-2\\java02-0921\\day22网络编程基础\\src\\com\\wanxi\\tcp\\demo4客户端发送文件给服务器\\ReadMe.java";
        InputStreamReader localReader = new FileReader(path);
        int content = 0;
        //3 创建输出流
        Writer outputStream = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
//        OutputStream outputStream=new BufferedOutputStream(socket.getOutputStream());
        while ((content = localReader.read()) != -1) {
            outputStream.write(content);
            outputStream.flush();

        }
        outputStream.close();
        socket.close();
        // 输出数据
        System.out.println("tcp 客户端传输完毕......");

    }
}
